package com.nl.controller.xuyi.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.nl.controller.common.model.Response;
import com.nl.controller.common.util.ResponseUtil;
import com.nl.controller.web.bean.SmsUsers;
import com.nl.controller.web.bean.XuYiStation;
import com.nl.controller.xuyi.service.XuYiRegionService;

import lombok.extern.slf4j.Slf4j;
	
@Slf4j
@RequestMapping("/xuYiRegion")
@RestController
public class XuYiRegionController {
	@Autowired
	XuYiRegionService xuYiRegionService;
	    
    @PostMapping("findRegionNameByPath")
    public Response<String> findRegionNameByPath(@RequestParam(value = "pathName", required = false) String pathName
    		) {
        	List<String> list = new ArrayList<String>();
        	list = xuYiRegionService.findRegionNameByPath(pathName);
        
        log.debug("根据路线名查询已关联点位名返回数据：{}", list.size());
        return ResponseUtil.sucess(list);
    }  
    
    
    @RequestMapping("findRegionNameList") 
    public Response findRegionNameList(
    		@RequestParam(value = "page", required = true) int page,
            @RequestParam(value = "limit", required = true) int limit,
    		@RequestParam(value = "regionName",required=false) String regionName){
    		PageInfo<XuYiStation> pageInfo = xuYiRegionService.findRegionNameList(page,limit,regionName);
    	    return ResponseUtil.sucess(pageInfo.getList(), pageInfo.getTotal());
    }
    
    @RequestMapping("regionModify")
    public Response regionModify(
    		@RequestParam(value = "regionName",required=false) String regionName,
    		@RequestParam(value = "lnglatList",required=false) String lnglatList,
    		HttpSession session
    		){
    		SmsUsers user = (SmsUsers) session.getAttribute("user");
    		String operatorTel = user.getMsisdn();
    		int modifyResult = xuYiRegionService.regionModify(regionName,lnglatList,operatorTel);
    		
    	    return ResponseUtil.sucess(modifyResult);
    }
    
    
   

}
